/**
 * Copyright 2009-2011 the original author or authors.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.myjung.hibernate.dialect;

import java.sql.Types;

import org.hibernate.HibernateException;

/**
 * @author Steve M. Jung
 */
public class DB2Dialect extends org.hibernate.dialect.DB2Dialect {
	public DB2Dialect() {
		super();
	}
	public String getTypeName(int code, int length, int precision, int scale) throws HibernateException {
		// validate the length
		if (length < 1 || length > 99999) {
			length = 1024;
		}
		// seed the typename
		String result = super.getTypeName(code, length, precision, scale);
		if (code == Types.CLOB) {
			StringBuffer buffer = new StringBuffer(8);
			buffer.append(result.substring(0, result.indexOf(")")));
			switch (scale) {
			case 0:
				buffer.append(" ");
				break;
			case 1:
				buffer.append(" K ");
				break;
			case 2:
				buffer.append(" M ");
				break;
			case 3:
				buffer.append(" G ");
				break;
			default:
				buffer.append(" M ");
				break;
			}
			buffer.append(")");
			result = buffer.toString();
		}
		return result;
	}
}